// pages/article/article.js
var WxParse = require('../wxParse/wxParse.js');
Page({
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getNewsDetail(options.newsid)
  },
  getNewsDetail(newsid) {
    var that = this;
    wx.request({
      url: 'http://192.168.0.108:9533/api/detail',
      data: {
        id: newsid,
        pageSize:10
      },
      success: (res) => {
        let newsArticle = res.data.data
        let newsDate = new Date(newsArticle.create_time)
        let sourceText = (newsArticle.source == "") ? "未知来源" : newsArticle.source
        let dateText = `${newsDate.getFullYear()}-${newsDate.getMonth()+1}-${newsDate.getDate()} ${newsDate.getHours()}:${(newsDate.getMinutes() < 10 ? '0' : '') + newsDate.getMinutes()}`
        
        let news = {
          title: newsArticle.title,
          date: dateText,
          source: sourceText,
          content: newsArticle.content,
          readCount: newsArticle.read,
          type:'p'
        }
        WxParse.wxParse('article', 'html', news.content, that,5);
        this.setData({
          news: news
        })
      }
    })
  }
})